package cn.group.controller;

import cn.group.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.entity.Manager;
import utils.BaseController;

import javax.servlet.http.HttpServletResponse;


@Api(tags = "管理员管理")
@Controller
@RequestMapping(value = "/manager", produces = "text/html;charset=utf-8")
public class ManagerController extends BaseController {
    @Autowired
    private ManagerService managerService;

    //查询所有管理员
    @ApiOperation("查询所有管理员")
    @RequestMapping("searchAllManagers.do")
    @ResponseBody
    public String searchAllManagers(HttpServletResponse resp) {
        System.out.println("查询所有管理员");
        return writerSuccessResult(managerService.searchAllManagers(), resp);
    }

    //通过名字查询管理员信息
    @ApiOperation("通过名字查询管理员信息")
    @RequestMapping("searchManagerByName.do")
    @ResponseBody
    public String searchManagerByName(String managerName, HttpServletResponse resp) {
        System.out.println("通过名字查询管理员信息" + managerName);
        return writerSuccessResult(managerService.searchManagerByName(managerName), resp);
    }

    //通过id查询管理员信息
    @ApiOperation("通过id查询管理员信息")
    @RequestMapping("searchManagerById.do")
    @ResponseBody
    public String searchManagerById(Long managerId, HttpServletResponse resp) {
        System.out.println("通过id查询管理员信息" + managerId);
        return writerSuccessResult(managerService.searchManagerById(managerId), resp);
    }


    //通过ID删除管理员信息(设状态为不可用)
    @ApiOperation("通过ID删除管理员信息")
    @RequestMapping("deleteByManagerId.do")
    @ResponseBody
    public String deleteByManagerId(Long managerId, HttpServletResponse resp) {
        System.out.println("通过ID删除管理员信息" + managerId);
        return writerSuccessResult(managerService.deleteManagerById(managerId), resp);
    }

    //修改管理员信息
    @ApiOperation("修改管理员信息")
    @RequestMapping("updateManager.do")
    @ResponseBody
    public String updateManager(Manager manager, HttpServletResponse resp) {
        System.out.println("修改管理员信息" + manager);
        return writerSuccessResult(managerService.updateManager(manager), resp);
    }
    //新增管理员
    @ApiOperation("新增管理员")
    @RequestMapping("addManager.do")
    @ResponseBody
    public String addManager(Manager manager,HttpServletResponse resp){
        System.out.println("新增管理员"+manager);
        return writerSuccessResult(managerService.addManager(manager),resp);
    }
}
